<template>
	<view>
		<view class="order-top">
			<view class="order-tabbar">
				<liuyuno-tabs :tabData="tabs" :activeIndex="tabCur" @tabClick='selectTab' class="nav" />
			</view>
		</view>
		<view class="order-list">
			<view class="order" v-for="item in list" :key="item.id" @click="goDetail(item.id)">
				<view class="order-item">
					<view class="commodity">
						<view class="status">
							<!-- <text style="background: #999;border-radius: 50%;"> -->
							<uni-icons type="shop" color="#bfbfbf" size="20" style="margin-right: 5px;"></uni-icons>
							<!-- </text> -->
							{{item.status_text}}
						</view>
						<view class="delivery">
							{{item.created_at}}
						</view>
					</view>
					<view class="details" v-for="(detail,index) in item.order_detail">
						<view class="details-l">
							<image :src="detail.product_sku_image" mode="widthFix">
							</image>
						</view>
						<view class="details-r">
							<view class="title line2">
								{{detail.product_title}}
							</view>
							<view class="skubar">
								<text class="sku">规格:{{detail.product_sku_title}}</text>
								<text class="price">￥{{detail.product_sku_price}}</text>
							</view>
							<view class="othing">
								<text class="num">共{{detail.product_amount}}件</text>
							</view>
						</view>
					</view>
					<view class="action">
						<view class="price">
							实付 <text>￥{{item.real_fee_text}}</text>
						</view>
						<view class="btn-group">
							<view class="cbtn" @click.stop="handldeChat(item.phone)">联系天使员</view>
							<view class="cbtn" @click="orderDetail(item.id)">
								查看详情
							</view>
							<view class="cbtn" @click.stop="handldeReminder(item.id)">催单</view>
						</view>

					</view>
				</view>
			</view>
		</view>
		<view class="empty" v-if="list.length==0">
			<image src="../../static/empty.png" mode=""></image>
			<view>暂无相关订单～～</view>
		</view>
		<orderStatus :show="show" @closePopup="closePopup"></orderStatus>

	</view>
</template>

<script>
	import orderStatus from '../../components/onTakeOrder/onTakeOrder.vue'
	export default {
		components: {
			orderStatus
		},
		data() {
			return {
				show: false,
				tabs: [{
						id: 0,
						name: '全部'
					},
					{
						id: 1,
						name: '待服务'
					},
					{
						id: 2,
						name: '服务中'
					},
					{
						id: 3,
						name: '待评价'
					},
					{
						id: 4,
						name: '已完成'
					}
				],
				tabCur: 0,
				list: [],
				page: 1,
			};
		},
		onShareAppMessage() {},
		onShareTimeline() {},
		onLoad(e) {
			if (!uni.getStorageSync('openid')) {
				uni.switchTab({
					url: '../user/user'
				})
				return
			}
			this.$api.orderov({
				openid: uni.getStorageSync('openid')
			}).then(res => {
				if (res.code == 1) {
					if (res.data.status == 1) {
						this.show = true
					}
				}
			})

			if (e.status) {
				this.tabCur = e.status
			} else {
				this.tabCur = 0
			}

			this.page = 1
			this.list = []
			this.getList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getList()
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {
			closePopup() {
				this.show = false
			},
			selectTab(id) {
				this.page = 1
				this.tabCur = id
				this.list = []
				this.getList()
			},
			getList() {
				this.$api.shopOrder({
					page: this.page,
					openid: uni.getStorageSync('openid'),
					status: this.tabCur
				}).then(res => {
					this.list.push(...res.data)
				})
			},
			goDetail(id) {
				uni.navigateTo({
					url: '../order-detail/order-shop-detail?orderid=' + id
				})
			},

		}
	}
</script>

<style lang="scss">
	.tab {
		position: fixed;
		left: 0;
		top: 0;
		/* #ifdef H5 */
		top: var(--staus-bar);
		/* #endif */
		right: 0;
		z-index: 100;
		line-height: 88upx;
		display: flex;
		justify-content: space-between;
		background: #fff;

		.item {
			flex: 1;
			text-align: center;
			font-size: 30upx;
			color: #979797;
		}

		.cur {
			color: #fff;
			background: $color-primary;
		}
	}

	.order {
		margin: 20upx;
	}

	.order-top {
		position: sticky;
		top: 0;
		z-index: 10;
		background: #fff;
		padding: 20rpx 0;
	}

	.order-item {
		background: #fff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;

		.commodity {
			height: 100rpx;
			margin: 0 25rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 24rpx;

			.status {
				font-weight: bold;
				display: flex;
				align-items: center;
			}
		}

		.details {
			margin: 0 25rpx;
			padding: 30rpx 0;
			display: flex;
			border-bottom: 1rpx solid #e5e5e5;
			border-top: 1rpx solid #e5e5e5;

			.details-l {
				width: 140rpx;
				height: 140rpx;
				border-radius: 10rpx;
				overflow: hidden;
			}

			.details-r {
				flex: 1;
				margin-left: 22rpx;
				display: flex;
				flex-direction: column;
				font-size: 24rpx;

				.skubar,
				.othing {
					display: flex;
					justify-content: space-between;
					margin-top: 30rpx;
				}

				.othing {
					margin-top: 14rpx;
				}

				.sku,
				.num {
					color: $uni-text-color-grey;
				}


			}
		}

		.action {
			display: flex;
			justify-content: flex-end;
			align-items: center;

			.price {
				font-size: 28rpx;
				flex: 1;
				margin-left: 40upx;
			}

			.btn-group {
				display: flex;
				justify-content: flex-end;
				align-items: center;
				height: 100rpx;
				padding: 0 20rpx;

				.cbtn {
					color: $theme-color;
					padding: 5upx 10upx;
					border: 1rpx $theme-color solid;
					border-radius: 40upx;
					margin-left: 20upx;
				}
			}
		}

	}
</style>